import tcsy.request_api as request


# 添加账户
def add(session, domain, account_name, account_type, account_balance):
    url = domain + '/tp-api/account.php/account/add'
    account_data = {
        "name": account_name,
        "type": account_type,
        "balance": account_balance,
    }
    return request.request_api(session, url, **account_data)


# 编辑账户
def edit(session, domain, account_id, account_name, account_type, account_balance):
    url = domain + '/tp-api/account.php/account/edit'
    account_data = {
        "id": account_id,
        "name": account_name,
        "type": account_type,
        "balance": account_balance,
    }
    return request.request_api(session, url, **account_data)


# 删除账户
def delete(session, domain, account_id):
    url = domain + '/tp-api/account.php/account/delete'
    account_data = {
        "id": account_id
    }
    return request.request_api(session, url, **account_data)


# 账户列表
def account_list(session, domain):
    url = domain + '/tp-api/account.php/account/AccountList'
    request.request_api(session, url)
    return request.request_api(session, url)


def test_account(session, domain):
    data = {
        "name": "招商银行卡",
        "type": 1,
        "balance": 390,
    }
    result = add(session, domain, data['name'], data['type'], data['balance'])
    print(result)


def test_account_list(session, domain):
    result = account_list(session, domain)
    print(result)


def test_account_edit(session, domain):
    data = {
        "id": '2',
        "name": "支付宝借呗",
        "type": 2,
        "balance": 3000,
    }
    result = edit(session, domain, data['id'], data['name'], data['type'], data['balance'])
    print(result)


def test_account_delete(session, domain):
    data = {
        "id": 3
    }
    result = delete(session, domain, data['id'])
    print(result)


